from socket import socket, AF_INET, SOCK_STREAM

def start_client():
    client = socket() #客户端直接定义一个socket无须指定tcp
    host = '127.0.0.1'
    port = 9999
    client.connect((host, port))    #连接服务器
    print(f'已连接到{host}:{port}')
    send_data = ''
    rec_data = ''
    while send_data != 'bye' and rec_data != 'bye':
        send_data = input(f"请输入要发送的数据：")

        client.sendall(send_data.encode('utf-8'))
        if send_data == 'bye':
            break
        rec_data = client.recv(1024).decode('utf-8')
        print(f'接受到的数据是：',rec_data)
    client.close()

if __name__ == '__main__':
    start_client()